<template>
  <div class="home-page">
    <h1 class="page-title">欢迎来到首页!</h1>
    <router-link to="/profile" class="home-link">个人简介</router-link>
    <router-link to="/codelover" class="home-link">课程选择</router-link>
    <router-link to="/score" class="home-link">个人成绩</router-link>
    <el-row :gutter="20" class="home-content">
      <el-col :span="24">
        <Gitee />
      </el-col>
      <el-col v-if="isLoggedIn" :span="12">
        <TodoList />
      </el-col>
      <el-col :span="12">
        <OddSumCalculator :oddSum="oddSum" @update:oddSum="oddSum = $event" />
      </el-col>
      <el-col :span="24" v-if="isLoggedIn">
        <el-button class="logout-button" type="primary" @click="logout">注销</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { ref, computed } from 'vue';
import { useAuthStore } from '@/stores/auth';
import Gitee from './Gitee.vue';
import TodoList from './TodoList.vue';
import OddSumCalculator from './OddSumCalculator.vue';
import { useRouter } from 'vue-router';

export default {
  name: 'Home',
  components: {
    TodoList,
    OddSumCalculator,
    Gitee
  },
  setup() {
    const authStore = useAuthStore();
    const isLoggedIn = computed(() => authStore.isLoggedIn);
    const oddSum = ref(0);
    const router = useRouter();

    const logout = () => {
      authStore.logout();
      router.push('/login');
    };

    return {
      isLoggedIn,
      oddSum,
      logout
    };
  }
};
</script>

<style scoped>
 .home-link{
    margin-right: 20px;
  }
body, html {
  height: 100%;
  margin: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f5f5f5;
}

.home-page {
  width: 90%;
  max-width: 1200px;
  background: linear-gradient(135deg, #fce4fc, #e9b9f2);
  color: #333;
  font-family: 'Arial', sans-serif;
  border-radius: 10px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
  padding: 20px;
  margin-top: 2rem;
}

.page-title {
  font-size: 2.5rem;
  font-weight: bold;
  text-align: center;
  margin-bottom: 20px;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-around;
  width: 100%;
}

@media (max-width: 768px) {
  .home-page {
    padding: 10px;
  }

  .page-title {
    font-size: 2rem;
    margin-bottom: 10px;
  }

  .logout-button {
    padding: 8px 15px;
    font-size: 1rem;
  }
}

@media (min-width: 769px) {
  .home-content {
    flex-direction: row;
    justify-content: space-around;
  }

  .todo-container, .calculator-container {
    flex: 1;
    margin: 0 10px;
  }
}

.todo-container, .calculator-container {
  margin-bottom: 20px;
}

.logout-button {
  padding: 10px 20px;
  border: none;
  border-radius: 5px;
  background-color: #ec9bd1;
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.logout-button:hover {
  background-color: #dd7ba9;
}

.router-link-active {
  color: #000;
}
</style>